// 设置导航样式
export default function useSetStyle() {
	const setDotStyle = (index, show) => {
		let pages = getCurrentPages();
		let page = pages[pages.length - 1];
		// #ifdef APP-PLUS
		let currentWebview = page.$getAppWebview();
		if (show) {
			currentWebview.showTitleNViewButtonRedDot({
				index: index,
				text: 1
			})
		} else {
			currentWebview.hideTitleNViewButtonRedDot({
				index: index
			})
		}
		// #endif
	}

	const setBadgeStyle = (index, msgCount) => {
		let show = msgCount > 0
		let text = msgCount > 99 ? "99+" : `${msgCount}`
		let pages = getCurrentPages();
		let page = pages[pages.length - 1];
		// #ifdef APP-PLUS
		let currentWebview = page.$getAppWebview();
		if (show) {
			currentWebview.setTitleNViewButtonBadge({
				index: index,
				text: text
			})
		} else {
			currentWebview.removeTitleNViewButtonBadge({
				index: index
			})
		}
		// #endif
	}
	
	//隐藏当前页右上角按钮，
	//@param index 按钮索引
	//@param show 是否显示 true | false
	const hideButton = (index, show) => {
		let pages = getCurrentPages();
		let page = pages[pages.length - 1];
		// #ifdef APP-PLUS
		let currentWebview = page.$getAppWebview();
		let width = show ? "24" : "0"
		currentWebview.setTitleNViewButtonStyle(index, {
			"width": width
		})
		// #endif
	}

	return {
		setDotStyle,
		setBadgeStyle,
		hideButton
	}
}